package com.dz.order.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.dz.customer.entity.SmsSenderVO;
import com.dz.order.OrderVO;
import com.dz.order.entity.Order;
import com.dz.order.service.CustomerService;
import com.dz.order.service.OrderService;

/**
 * <p>
 * 订单基础表 前端控制器
 * </p>
 *
 * @author star
 * @since 2017-06-27
 */
@RestController
@Api(description="下单接口")
public class OrderControler {

	@Autowired
	private CustomerService customerService;

	@Autowired
	private OrderService orderService;

	@RequestMapping(value="/createOne",method=RequestMethod.POST)
	@ApiOperation(value="申请第一步",httpMethod="POST")
	public Order createOrder(@RequestBody OrderVO orderVO) {
		Assert.notNull(orderVO.getCode(), "验证码不能为空");
		// 验证手机号
		boolean flag = customerService.verifyCode(new SmsSenderVO(orderVO.getMobile(), orderVO.getCode()));
		Assert.isTrue(flag, "验证码错误");
		return orderService.addOrder(orderVO);
	}

	@RequestMapping("/confirmOrder")
	@ApiOperation(value="申请第二步",httpMethod="POST")
	public boolean confirmOrder(@RequestBody OrderVO orderVO) {
		return orderService.confirmOrder(orderVO);
	}
}
